#ifndef G_CODE_H
#define G_CODE_H
#include "cx_typedef.h"
#ifdef __cplusplus
extern "C"{
#endif
#define G_CODE_FLAGS_FUNC_INSTRUMENT_MASK 0x00000003
#define G_CODE_FLAGS_G_BIT (0x00000001<<0)
#define G_CODE_FLAGS_M_BIT (0x00000001<<1)


#define G_CODE_FLAGS_T_BIT (0x00000001<<2)
#define G_CODE_FLAGS_X_BIT (0x00000001<<3)
#define G_CODE_FLAGS_Y_BIT (0x00000001<<4)
#define G_CODE_FLAGS_Z_BIT (0x00000001<<5)
#define G_CODE_FLAGS_I_BIT (0x00000001<<6)
#define G_CODE_FLAGS_J_BIT (0x00000001<<7)
#define G_CODE_FLAGS_K_BIT (0x00000001<<8)
#define G_CODE_FLAGS_R_BIT (0x00000001<<9)

#define G_CODE_FLAGS_F_BIT (0x00000001<<10)
#define G_CODE_FLAGS_S_BIT (0x00000001<<11)

#define G_CODE_FLAGS_N_BIT (0x00000001<<12)

#define G_CODE_FLAGS_L_BIT (0x00000001<<13)
#define G_CODE_FLAGS_Q_BIT (0x00000001<<14)

#define G_CODE_FLAGS_D_BIT (0x00000001<<15)
#define G_CODE_FLAGS_H_BIT (0x00000001<<16)

#define G_CODE_FLAGS_O_BIT (0x00000001<<17)

#define G_CODE_FLAGS_G_SUB_GROUP_BIT (0x00000001<<18)

#define G_CODE_FLAGS_U_BIT (0x00000001<<19)
#define G_CODE_FLAGS_V_BIT (0x00000001<<20)
#define G_CODE_FLAGS_W_BIT (0x00000001<<21)

#define G_CODE_FLAGS_REPEAT_ERR_BIT  (0x00000001<<22)
#define G_CODE_FLAGS_ERR_MASK        (G_CODE_FLAGS_REPEAT_ERR_BIT)


#define G_CODE_COORDS_MODE_RELATIVE 0
#define G_CODE_COORDS_MODE_ABSOLUTE 1

#define COORDINATE_1 0
#define COORDINATE_2 1
#define COORDINATE_3 2
#define COORDINATE_4 3
#define COORDINATE_5 4
#define COORDINATE_6 5


#define PLANE_X_Y 0
#define PLANE_X_Z 1
#define PLANE_Y_Z 2

#define G_CODE_INTERPOLATOR_QUICK 0
#define G_CODE_INTERPOLATOR_LINE 1
#define G_CODE_INTERPOLATOR_CW 2
#define G_CODE_INTERPOLATOR_CCW 3
#define G_CODE_INTERPOLATOR_SPIRAL 4
#define G_CODE_INTERPOLATOR_SPLINE 5

#define G_CODE_INTERPOLATOR_SET_REFERENCE_COOR 6
#define G_CODE_INTERPOLATOR_BUILD_RADIUS_COMPENSATION 7
typedef int g_code_sys_status_t;

typedef struct g_code_param
{

    float x;
    float y;
    float z;
    float i;
    float j;
    float k;
    float r;

    float f;
    float s;

    float u;
    float v;
    float w;

    cx_uint16_t t;
    cx_uint16_t g;
    cx_uint16_t sub_g;
    cx_uint16_t m;

    void *other;
    cx_uint32_t flags;
}g_code_param_t;

typedef struct g_comg_code_command_tmand
{
    char cmd;
    union 
    {
        float f_value;
        struct 
        {
            cx_uint16_t value;
            cx_uint16_t sub_value;
        }i_value;
        // void * other;
    };
}g_code_command_t;

typedef int (*g_code_handler_t)(g_code_param_t *param);


extern g_code_sys_status_t g_code_coords_mode;

extern g_code_sys_status_t g_code_current_coords;

extern g_code_sys_status_t g_code_work_plane;
cx_uint32_t g_code_get_param(char *g_code_line, g_code_param_t *ret_param);
extern float (*g_code_interpolate_handler[])(g_code_param_t*param);

#define G_CODE_TRANSLATOR_FLAG_OK_MASK 0x01
#define G_CODE_TRANSLATOR_FLAG_OK_TRUE 0x00
#define G_CODE_TRANSLATOR_FLAG_OK_FALSE 0x01
extern int g_code_translator_flags;
int g_code_handler_init(void);
void interpolator_Handler(void);
#ifdef __cplusplus
}
#endif
#endif